package TEST;

import static org.junit.Assert.*;

import java.net.Socket;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import Server.Server;

public class ServerTest {
	private TestServer s;

	@Before
	public void setUp() throws Exception {
		s = new TestServer();
	}

	@After
	public void tearDown() throws Exception {
		s.stop();
	}

	@Test
	public void PortTest() {
		assertEquals(s.getPort(), 8888);
	}
	
	@Test
	public void ClientAcceptedTest() throws Exception {
		new Thread(s).start();
		new Socket("localhost", Server.DEFAULT_SERVER_PORT);
		TestUtil.waitForSuccess(new RunnableWithExceptions() {
			@Override
			public void run() {
				assertTrue(s.clientAccepted);
			}
		});
	}
}
